package com.wwj.core.wawa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wwj.core.wawa.entity.Banner;
import com.wwj.core.wawa.entity.mapper.BannerMapper;
import com.wwj.core.wawa.service.IBannerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by Auser on 2017/11/8.
 */
@Service
public class BannerServiceImpl implements IBannerService {
    @Resource
    private BannerMapper bannerMapper;


    @Override
    public Banner findById(int id) throws Exception {
        return bannerMapper.findById(id);
    }

    @Override
    public Page<Banner> findByPage(Map<String, Object> params,int offset,int limit) throws Exception {
        PageHelper.offsetPage(offset,limit);
        return (Page)bannerMapper.selectBannerByPage(params);
    }

    @Override
    public void createBanner(Banner banner) throws Exception {
        bannerMapper.createBanner(banner);
    }

    @Override
    public void updateBanner(Banner banner) throws Exception {
        Banner b = bannerMapper.findById(banner.getId());
        b.setTitle(banner.getTitle());
        b.setPicUrl(banner.getPicUrl());
        b.setPicThumbnailUrl(banner.getPicThumbnailUrl());
        b.setStatus(banner.getStatus());
        b.setTargetUrl(banner.getTargetUrl());

        bannerMapper.updateBanner(banner);
    }

    @Override
    public void deleteBannerById(Integer id) throws Exception {
        bannerMapper.deleteBannerById(id);
    }
}
